package loginutils

import (
	"errors"
	"hft/Http/Models/request"
	"hft/Http/Services/login"
	"hft/e"
	"hft/global"
	"hft/tools"
)

// var model string
// var res = tools.CheckPhoneNumber(account.Phone)
// if res == 0 {
// 	model = global.OC_CONFIG.AliyunSms.SmsModel
// } else if res == 1 || res == 2 {
// 	model = global.OC_CONFIG.AliyunSms.SmsHKModel
// 	if res == 1 {
// 		account.Phone = "852" + account.Phone
// 	} else {
// 		account.Phone = "853" + account.Phone
// 	}
// } else {
// 	return errors.New(e.PhoneNotRight)
// }

// 手机登录
func Phone(userType string, account *request.Login) (token string, err error) {
	var res = tools.CheckPhoneNumber(account.Phone)
	if res == 3 {
		return "", errors.New(e.PhoneNotRight)
	}
	// 验证码
	err = tools.AliyunSmsTool.VerifyValid(global.OC_CONFIG.AliyunSms.LoginSend, account.Phone, account.Code)
	if err != nil {
		return "", err
	}

	token, err = login.LoginService.NormalLogin("phone", account.Phone, userType)
	if err != nil {
		return "", err
	}

	return token, nil
}

// 微信登录
func WX(userType string, account *request.Login) (err error) {

	return nil
}
